package com.baidu.common.util;

import com.baidu.common.exception.WebException;

import java.io.IOException;
import java.util.Properties;

/**
 * @Author: BSS
 * @create: 2020/8/19/19:18
 */
public class PropertiesUtil {
    private static final Properties properties = new Properties();

    private PropertiesUtil(){}

    static {
        try {
            properties.load(PropertiesUtil.class.getResourceAsStream("/JdbcInfo.properties"));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void reload(String path) throws WebException {
        try {
            properties.load(PropertiesUtil.class.getResourceAsStream(path));
        } catch (IOException e) {
            e.printStackTrace();
            throw new WebException(e.getMessage());
        }
    }

    public static String getString(String key) throws WebException {
        return properties.getProperty(key);
    }

    public static void main(String[] args) throws WebException {
        System.out.println(getString("key"));

        String sql = getString( "key");
        System.out.println(sql);
    }
}
